<template>
    <div class="pad">
        <!-- search start -->
        <!--<searchBar @handleSearch="init"/>-->
        <!-- search end -->
        <!-- table start -->
        <tableDataEl
                :page.sync="page"
                :pageSize="pageSize"
                :tableData="tableData.list"
                :tableLabel="tableLabel"
                :pageCount="tableData.rows"
                ImgText="支付凭证"
                v-loading="loading"
                @viewsRegions="viewsRegions"
                @handleDetail="handleDetail"
                height="89vh"
        />
        <!-- table end -->
        <!-- dialog start -->
        <el-dialog
                :visible.sync="isShowRegions"
                center
                title="区域"
                width="40%"
                v-el-drag-dialog
        >
            <el-table
                    :data="regionsData"
                    border
                    height="250"
                    v-loading="regionsLoading"
            >
                <el-table-column
                        label="省"
                        prop="name"
                        align="center"
                />
                <el-table-column
                        label="市"
                        align="center"
                >
                    <template slot-scope="scope">
                        {{scope.row['children'][0]['name']}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="区"
                        align="center"
                >
                    <template slot-scope="scope">
                        {{scope.row['children'][0]['children'][0]['name']}}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
        <!-- dialog end -->
    </div>
</template>

<script>
    import tableDataEl from '@/views/Setup/common/table'
    export default {
        name: "rejected",
        components: {
            tableDataEl
        },
        data () {
            return {
                page: 1,
                pageSize: 8,
                tableData: {},
                tableLabel: [
                    {
                        label: '运营商名称',
                        prop: 'company'
                    },
                    {
                        label: '联系方式',
                        prop: 'phone'
                    },
                    {
                        label: '负责人',
                        prop: 'leader'
                    },
                    {
                        label: '支付凭证',
                        prop: 'usecost',
                        image: true
                    },
                    {
                        label: '区域',
                        prop: 'regions',
                        detail: true,
                        methodName: 'viewsRegions'

                    },
                    {
                        label: '申请时间',
                        prop: 'create_time'
                    },
                    {
                        label: '审核时间',
                        prop: 'audit_time'
                    }
                ],
                loading: false,
                isShowRegions: false,
                regionsData: [],
                regionsLoading: false,
                isShowDetail: false,
                detailData: {},
                detailLoading: false
            }
        },
        methods: {
            async init () { //初始化
                this.loading = true;
                // let paramsStr = Object.assign(search, {page: this.page, pageSize: this.pageSize})
                let res = await this.api.log_o_rejected({page: this.page, pageSize: this.pageSize});
                res.code ? this.tableData = res.data : this.$message(res.msg);
                this.loading = false;
            },
            async viewsRegions (...value) {  //查看区域
                this.regionsLoading = true;
                this.isShowRegions = true;
                let res = await this.api.detailArea({id: value[1]['id']});
                if(res.code) {
                    this.regionsData = typeof res.data === 'string' ? [] : res.data;
                    this.regionsLoading = false;
                } else this.$message(res.msg);
            },
            async handleDetail (...value) { //查看详情
                this.isShowDetail = true;
                this.detailLoading = true;
                let res = await this.api.applicationDetail({id: value[1]['id'], aid: value[1]['aid']});
                res.code ? this.detailData = res.data : this.$message(res.msg);
                this.detailLoading = false;
            }
        },
        mounted () {
            this.init()
        },
        watch: {
            page () {
                this.init()
            },
            pageSize () {
                this.init()
            }
        }
    }
</script>

<style scoped>
    .pad {
        padding: 10px;
    }
    .el-form-item {
        margin-bottom:10px;
    }
</style>
